package com.imooc.follow.controller;

import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.imooc.commons.model.domain.ResultInfo;
import com.imooc.commons.utils.ResultInfoUtil;
import com.imooc.follow.service.FollowService;

/**
 * \* @author: bear
 * \* Date: 2021-08-04-14:15
 * \* describe:
 */
@RestController
public class FollowController {

	@Resource
	private FollowService followService;
	@Resource
	private HttpServletRequest request;

	/**
	 * 关注---取关
	 *
	 * @param followDinerId 关注的 up主id
	 * @param isFollowed 是否关注 1= 关注，0= 取关
	 * @param access_token 登录用户token
	 *
	 * @return
	 */
	@PostMapping("/follow")
	public ResultInfo follow(@RequestParam Integer followDinerId, @RequestParam int isFollowed, String access_token) {
		ResultInfo resultInfo = followService.follow(followDinerId, isFollowed, access_token, request.getServletPath());
		return resultInfo;
	}

	/**
	 * 共同好友接口
	 */
	@GetMapping("commons")
	public ResultInfo findCommonsFriends(@RequestParam Integer dinerId, String access_token) {
		ResultInfo resultInfo = followService.findCommonsFriends(dinerId, access_token, request.getServletPath());
		return resultInfo;
	}

	/**
	 * 关注列表
	 * @param access_token
	 * @return
	 */
	@GetMapping("myList")
	public ResultInfo myList( String access_token) {
		Integer type =1;
		ResultInfo resultInfo = followService.myList( access_token, request.getServletPath(),type);
		return resultInfo;
	}

	/**
	 * 粉丝列表
	 * @param access_token
	 * @return
	 */
	@GetMapping("funList")
	public ResultInfo funList( String access_token) {
		Integer type =2;
		ResultInfo resultInfo = followService.myList( access_token, request.getServletPath(), type);
		return resultInfo;
	}

	@GetMapping("checkFollow")
	public ResultInfo checkFollow( String access_token,@RequestParam Integer dinerId) {
		ResultInfo resultInfo = followService.checkFollow( access_token, request.getServletPath(),dinerId);
		return resultInfo;
	}

	/**
	 * 获取粉丝列表
	 * 指定用户id
	 * @param dinerId
	 * @return
	 */
	@GetMapping("followers")
	public ResultInfo followers(Integer dinerId) {

		Set<Integer> followers = followService.findFollowers(dinerId);
		return ResultInfoUtil.buildSuccess(request.getServletPath(), followers);
	}

}

